//
//  Utility.h
//  CardBag
//
//  Created by 恒信 on 11-4-1.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>



#define kDEFAULT_DATE_TIME_FORMAT (@"yyyy-MM-dd HH:mm:ss")
#define kDEFAULT_DATE_FORMAT (@"yyyy-MM-dd")
#define kDEFAULT_TIME_FORMAT (@"HH:mm")
#define kDEFAULT_DATE_TIME_FORMAT2 (@"yyyyMMddHHmmss")
#define kDEFAULT_DATE_TIME_FORMAT3 (@"yyyy-MM-dd HH:mm")


//请求业务类型定义
typedef enum {
    DateFormatterDateAndTime,
    DateFormatterDate,
    DateFormatterTime,
    DateFormatterDateAndTime2,
    DateFormatterDateAndTime3
} DateFormatterStyle;


@interface Utility : NSObject
{
    
}

//格式话返回文件大小
+ (NSString *)stringForAllFileSize:(UInt64)fileSize;

+ (CGFloat)textHeightWithFont:(NSString *)text withFont:(UIFont *)font sizeWidth:(float)width;
+ (CGFloat)textHeightWithStirng:(NSString *)inputString ShowFont:(UIFont *)font TitleFrame:(CGRect)frame;
+ (CGFloat)textWidthWithStirng:(NSString *)inputString ShowFont:(UIFont *)font sizeHeight:(CGFloat)height;
//弹出alertview
+ (void)alert:(NSString *)msg;
+ (void)alert:(NSString *)title msg:(NSString *)msg;
+ (void)showError:(NSInteger)errNo errorMessage:(NSString *)errMsg;
//清除电话号码中无用字符
+ (NSString*) cleanPhoneNumber:(NSString*)phoneNumber;
//拨打电话
+ (void) makeCall:(NSString *)phoneNumber;
//telprompt可以回调原程序
+ (void) makeCallPrompt:(NSString *)phoneNumber;

//生成字符串的MD5字符串
+ (NSString*)md5:(NSString*)str; 
//生成文件的md5值
+(NSString *)file_md5:(NSString*) path;
//des加密
+(NSData *)DesEncryptWithKey:(NSData *)key data:(NSData *)data;
//des解密
+(NSData *)DesDecryptWithKey:(NSData *)key data:(NSData *)data;
//匹配Email地址的正则表达式
+(BOOL)checkIsEmail:(NSString *)str;
//判断用户名是否合法
+(BOOL)stringIsLegalName:(NSString *)str;
//判断密码是否合法
+(BOOL)checkIsLegalPassword:(NSString *)str;
//判断字符串为空
+(BOOL)stringIsNull:(NSString *)str;
//判断字符串长度（NSString类型字符串转换成类似ASCII编码的长度，如汉字2个字节，英文以及符号1个字节）
+ (int)convertToInt:(NSString*)strtemp;
//反转字符串  "123" -->"321"
+(NSString *)reverseString:(NSString *)str;
//url编码
+ (NSString*)URLencode:(NSString *)originalString stringEncoding:(NSStringEncoding)stringEncoding;
//格式化时间
+ (NSString *)stringFromDate:(NSDate *)date forDateFormatterStyle:(DateFormatterStyle)dateFormatterStyle;
//字符串转数字
+ (NSNumber *)stringToNumber:(NSString *)string;
//数字转字符串
+ (NSString *)numberToString:(NSNumber *)number;
////数字转字符串,保留有效小数位
+ (NSString *)numberToString:(NSNumber *)number fractionDigits:(NSInteger)fractionDigits;
//float后面无效的0
+(NSString *)changeFloat:(NSString *)stringFloat zeroLength:(NSInteger)len;
//获取时间戳
+ (NSString *)generateTimestamp;
//生成GUID
+ (NSString *)generateUUID;
//字符串转日期
+(NSDate *)NSStringDateToNSDate:(NSString *)string  forDateFormatterStyle:(DateFormatterStyle)dateFormatterStyle;
//获得星期几
+(NSString *)weekWithDate:(NSDate *)date;

//计算两个时间差的两个函数
+ (NSString *)intervalFromLastDate: (NSString *) dateString1  toTheDate:(NSString *) dateString2;

//根据文件名获取MD5
+ (NSString *) getMD5FromUrl:(NSString *)url;
//去掉字符串中所有空格
+ (NSString *) trimAllSpaceString:(NSString *)string;
+ (NSString *) trimLeftSpaceString:(NSString *)string;
+ (NSString *) trimRightSpaceString:(NSString *)string;

+ (NSString *) subString:(NSString *)string length:(NSInteger)len;
+ (NSString *) subStringWithRange:(NSString *)string range:(NSRange)range;
//
+ (NSString *) convertToString:(id)data;
+ (NSNumber *) convertToNumber:(id)data;
+ (NSNumber *) convertToNumber:(id)data defaultValue:(NSInteger)defaultValue;
+ (NSDate *) convertToDate:(id)data;
+ (NSDate *) convertToDate:(id)data forDateFormatter:(NSString *)dateFormatter;
+ (BOOL) convertToBool:(id)data;

// Remove CoreData Sqlite File
+ (BOOL) removeSqliteFile;

+ (NSString *) convertImageToBase64:(NSData *)imageData;
+ (UIImage *) grayImage:(UIImage *)source;
+ (UIImage*)scaleToSize:(UIImage*)img size:(CGSize)size;
//地图两点之间距离
+ (double)getLantAndLongDist:(double)lon1 lat:(double)lat1 lon:(double)lon2 lat:(double)lat2;

//得到图片Image
+ (UIImage *)getImageFronSource:(NSString *)imgName Type:(NSString *)imgType;

// 判断手机号是否合法
+ (BOOL)validateMobile:(NSString *)mobileNum;

// 判断邮箱是否合法
+ (BOOL)validateEmail:(NSString *)candidate;

// 获取手机型号
+ (NSString*)getMobileOriginalModel;
+ (NSString*)getMobileModel;

// 获取IOS版本信息
+ (NSString*)getIOSVersion;

// 获取手机容量
+ (float)getMobileStroageSize;

// 获取手机屏幕尺寸
+ (NSString*)getMobileScreenSize;

// 获取手机屏幕分辨率
+ (NSString*)getMobileScreenPixelString;



#pragma -mark ------------------------通用小方法--------------
+ (BOOL)findSubstring:(NSString *)substr inString:(NSString *)dststr;

//将某一字符从开始位置截取到指定字符处
+ (NSString *)truncateNSString:(NSString *)srcStr To:(NSString *)toStr;
//去除用户Id字符串中的@wx.com  和 @group.wx.com
+ (NSString *)getBareContactId:(NSString *)contactId;

#pragma mark-------------------------通用处理方法-----------------------------
+ (NSString *)convertToJid:(NSString *)jidName;

+ (void)writeToFileWithString:(NSString *)aString withFileIsDelete:(BOOL)isDelete;

+ (BOOL)muteSwitchEnabled;


@end


//Categorys 为现有Cocoa类添加新方法
@interface UIColor(privateColor)
//可以传入#FFFFFF类型的颜色值
+ (UIColor *)colorwithString:(NSString *)colorValue colorAlpha:(float)alpha;

@end

